<!--
 * @Author: wangshiyang
 * @Date: 2023-06-15 16:03:18
 * @LastEditors: wangshiyang
 * @LastEditTime: 2023-06-15 16:06:33
 * @Description: 请填写简介
-->
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <!-- 1、导入mapbox的依赖 js+css -->
    <script src='https://api.mapbox.com/mapbox-gl-js/v2.14.1/mapbox-gl.js'></script>
    <link href='https://api.mapbox.com/mapbox-gl-js/v2.14.1/mapbox-gl.css' rel='stylesheet' />

    <style>
        * {
            margin: 0;
            padding: 0
        }

        #map {
            width: 100vw;
            height: 100vh;
        }
    </style>
</head>

<body>
    <!-- 2、设置地图容器的挂载点 -->
    <div id="map">

    </div>
    <script>
        /* 3、实例化地图 */
        mapboxgl.accessToken = 'pk.eyJ1IjoiemhvbmdkaXNodW1hIiwiYSI6ImNsNXJoYXR5eTI2bGgzZW53d2didWF1c3AifQ.6vOplM2NQc_xnJW3aA5ZBA';
        const map = new mapboxgl.Map({
            /* 将地图挂载到对应的DOM上 相当于ol的target */
            container: "map",
            /* 相当于ol的layers */
            style: {
                "version": 8,
                "sources": {
                    "raster-tiles": {
                        "type": "raster",
                        "tiles": ["http://webrd01.is.autonavi.com/appmaptile?lang=zh_cn&size=1&scale=1&style=8&x={x}&y={y}&z={z}"],
                        "tileSize": 256
                    }
                },
                "layers": [{
                    "id": "simple-tiles",
                    "type": "raster",
                    "source": "raster-tiles",
                    "minzoom": 0,
                    "maxzoom": 22
                }]
            },
            //俯仰角 默认是0 取值范围0~90
            //90度呈水平方向显示
            //pitch: 90,
            // 水平角 默认是0 取值范围-180~180
            bearing: 90,
            center: [114.30, 30.50],
            zoom: 6,
            projection: 'globe'
        })

        map.on("style.load", () => {
            map.setFog({
                /* 设置大气层的颜色 */
                "color": "#dc9f9f",
                /* 大气层之上的颜色 */
                "high-color": "#245bde",
                //定制化星空的颜色
                "space-color": "#333"
            })
        })
        // 测试水平角
        let isRotate = false
        let timer = null
        map.on("click", () => {
            isRotate = !isRotate;
            if (isRotate) {
                timer = setInterval(() => {
                    let bearing = map.getBearing();
                    console.log(bearing)
                    bearing++;
                    map.setBearing(bearing)
                }, 50)
            } else {
                map.stop();
                clearInterval(timer)
            }

        })
    </script>
</body>

</html>